package com.dtf.admin.staff.service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.dtf.admin.staff.vo.SystemStaff;
import com.dtf.core.common.dao.mysql.BaseDaoSupportForMysql;
import com.dtf.core.common.service.BaseService;
import com.dtf.core.common.utils.Const;
import com.dtf.core.common.utils.UUIDGenerator;
import com.dtf.core.common.vo.Pagination;

/**
 * 访问dao层的方式目前有三种
 * 1：继承baseService，可用super获取到Spring 的 jdbcTemplt工具类
 * 2:从super获取BaseDaoSupport获取到super.getDaoSupport().getNamedParameterJdbcTemplate()提供Spring内部封装的工具类
 * 3：从super获取BaseDaoSupport，系统内部自己对两个工具类进行的二次封装，主要用于分页查询等功能
 * @author Administrator
 *
 */
@Service
public class LoginService extends BaseService{
	
	private static Logger log = Logger.getLogger(LoginService.class);
	
	public SystemStaff login(String userName, String passWord) {
		String sql = "select * from system_staff where staff_code=? and password=? and status='0'";
		return (SystemStaff) super.queryBeanForSQL(sql, SystemStaff.class, new String[]{userName,passWord});
	}
	
	public List<Map<String, Object>> loadMenu(SystemStaff staff){
		String sql = "select distinct a.menu_id,a.menu_name,a.menu_url,a.menu_path,a.parent_id,a.status,a.sort_order,a.class_style,level " +
						"from system_privilege_rel b join system_menu a on a.menu_id = b.privilege_obj_id  " +
						"where b.privilege_type = 'menu' " +
						"and b.role_id in( " +
								"select c.role_id  " +
								"from system_staff_role_rel c join system_staff d on d.staff_id = c.staff_id  " +
								"where d.staff_id=? " +
						") order by a.sort_order";
		
		return super.getJdbcTemplate().queryForList(sql, new String[]{staff.getStaff_id()});
	}
}
